package com.yedean.operator.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.yedean.operator.entity.OperatorUser;
import com.yedean.operator.service.IOperatorUserService;
import com.yedean.operator.vo.LoginVo;
import com.yedean.utils.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.*;

/**
 * 管理员的登录接口
 *
 * @author yedean
 * @date 2022/9/14
 */
@RestController
@Slf4j
@Api(tags = {"管理员相关接口"})

public class UserController {

    @Reference(version = "1.0.0",check = false)
    private IOperatorUserService operatorUserService;

    @ApiOperation("分页列表查询")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "path",name= "page",value = "当前页码",required = true,dataType = "Integer"),
            @ApiImplicitParam(paramType = "path",name = "pageSize",value = "每页数据大小",required = true,dataType = "Integer"),
            @ApiImplicitParam(paramType = "query",name = "name",value = "用户名",required = false,dataType = "String"),
    })
    @GetMapping("/pageList/{page}/{pageSize}")
    public IPage<OperatorUser> findListByPage(@PathVariable("page") int pageNum,
                                              @PathVariable("pageSize") int pageSize,
                                              @RequestParam(value = "name",required = false) String name){
        return operatorUserService.queryPageByName(pageNum,pageSize,name);
    }

    //登录
    @ApiOperation("登录")
    @PostMapping("/login")
    @ApiImplicitParam(name = "Authorization", value = "jwt token", required = false, dataType = "String",paramType="header")
    public Result login(@RequestBody LoginVo loginVo){
        return operatorUserService.login(loginVo.getLoginName(),loginVo.getLoginPass());
    }
}
